/**
 * Created by duwei on 2018/11/17.
 */
var PlayerInfoCommonWindow = Window.extend({
    _ccsFileName: res.PlayerInfoCommonWindow_json,
    initWindow:function(){
        var self = this;
        this._initInfo();
        this._addEventListener(EventKey.Refresh_PlayerInfo, function () {
            self._refreshWindow();
        });
    },
    _initClickListeners: function () {
        this._super();
        this._clickListeners = {
            'btn_exit': '_clickExit',
            'btn_rengzheng': '_clickRenZheng',
            'btn_bangding': '_clickBD',
            'btn_xiugai': '_clickBD'
        };
    },
    /**
     * 初始化用户数据
     * @private
     */
    _initInfo: function () {
        this._nodeList['lb_nickname'].setString(gameData.nickname);
        this._nodeList['lb_id'].setString(gameData.uid);
        this._nodeList['lb_gid'].setString(gameData.gid);
        this._nodeList['lb_ip'].setString(gameData.ip);
        cc.log('LocationUtil.address===='+ LocationUtil.address);
        cc.log('gameData.location===='+ gameData.location);

        if (isNullString(LocationUtil.address)) {
            this._nodeList['lb_ad'].setString('您可能没有开启定位权限');
        } else {
            this._nodeList['lb_ad'].setString(ellipsisStr(decodeURIComponent(gameData.locationInfo), 16));
        }
        loadHeadImage(gameData.headimgurl, this._nodeList['head']);
        this._nodeList['female'].setVisible(gameData.sex != 1);
        this._nodeList['male'].setVisible(gameData.sex == 1);
        //判断绑定手机
        if (gameData.BDIphone == "" || gameData.BDIphone == null) { //未绑定手机
            this._nodeList['lab_iphone'].setVisible(false);
            this._nodeList['btn_xiugai'].setVisible(false);
        } else { //已绑定手机
            this._nodeList['btn_bangding'].setVisible(false);
            var iphone = gameData.BDIphone;
            iphone = iphone.replace(iphone.substr(3, 4), "****");
            this._nodeList['lab_iphone'].setString(iphone);
        }
        //判断实名认证
        if (!gameData.hasShiMing) { //未实名
            this._nodeList['had_renzheng'].setVisible(false);
        } else {
            this._nodeList['btn_rengzheng'].setVisible(false);
        }

    },
    _clickExit: function () {
        showMessageBox('是否确定退出登录？', function () {
            cc.sys.localStorage.removeItem('wx_openid');
            cc.sys.localStorage.removeItem('xl_openid');
            cc.sys.localStorage.removeItem('lb_openid');
            gameData.hasLogined = false;
            if (window.hasOwnProperty('isYaYaYule')) {
                cc.sys.localStorage.removeItem('current_app');
                network.disconnect(true);
            } else {
                network.disconnect();
            }
        });
    },
    _clickRenZheng: function () {
        showWindow('CertifiedWindow');
    },
    _clickBD: function () {
        showWindow('BDIphoneWindow', true);
    },
    _clickXiuGai: function () {
        showWindow('BDIphoneWindow', false);
    },
    _refreshWindow: function () {
        if (gameData.BDIphone.length > 0) { //绑定 改动 成功手机号
            this._nodeList['lab_iphone'].setVisible(true);
            this._nodeList['btn_bangding'].setVisible(false);
            var iphone = gameData.BDIphone;
            iphone = iphone.replace(iphone.substr(3, 4), "****");
            this._nodeList['lab_iphone'].setString(iphone);
            this._nodeList['btn_xiugai'].setVisible(true);

        } else { //解绑手机号
            this._nodeList['lab_iphone'].setVisible(false);
            this._nodeList['btn_xiugai'].setVisible(false);
            this._nodeList['btn_bangding'].setVisible(true);
            this._nodeList['btn_xiugai'].setVisible(false);

        }
        if (!gameData.hasShiMing) { //未实名
            this._nodeList['had_renzheng'].setVisible(false);
            this._nodeList['btn_rengzheng'].setVisible(true);

        } else {
            this._nodeList['had_renzheng'].setVisible(true);
            this._nodeList['btn_rengzheng'].setVisible(false);

        }
    }
});